﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using DSCop.Core;

namespace DSCop.Test
{
    /// <summary>
    /// Summary description for UnitTest1
    /// </summary>
    [TestClass]
    public class CommandLineArgumentsParserTest
    {
        public CommandLineArgumentsParserTest()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test 
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion

        [TestMethod]
        public void TestFileOnlyCommandParam()
        {
            //Init
            CommandLineArgumentsParser parser = new CommandLineArgumentsParser();

            //Act
            CommandArguments arguments = parser.Parse(new[] {"StageJob1.xml"});

            //Test
            Assert.IsNotNull(arguments);
            Assert.AreEqual("StageJob1.xml", arguments.FileName, true);
            Assert.IsNotNull(arguments.IncludeRules);
            Assert.AreEqual(0, arguments.IncludeRules.Count());
            Assert.IsNotNull(arguments.ExcludeRules);
            Assert.AreEqual(0, arguments.ExcludeRules.Count());
        }

        [TestMethod]
        [ExpectedException(typeof(CommandArgumentsException))]
        public void TestFileOnlyCommandParam_Negative()
        {
            //Init
            CommandLineArgumentsParser parser = new CommandLineArgumentsParser();

            //Act
            CommandArguments arguments = parser.Parse(new string[] { });
        }

        [TestMethod]
        public void TestIncludeRulsesCommandParam()
        {
            //Init
            CommandLineArgumentsParser parser = new CommandLineArgumentsParser();

            //Act
            CommandArguments arguments = parser.Parse(new[] { "StageJob1.xml", "-include", "StableSortRule", "PrefixNamingRule"});

            //Test
            Assert.IsNotNull(arguments);
            Assert.AreEqual("StageJob1.xml", arguments.FileName, true);
            Assert.IsNotNull(arguments.IncludeRules);
            Assert.AreEqual(2, arguments.IncludeRules.Count());
            Assert.AreEqual("StableSortRule", arguments.IncludeRules[0]);
            Assert.AreEqual("PrefixNamingRule", arguments.IncludeRules[1]);
            Assert.IsNotNull(arguments.ExcludeRules);
            Assert.AreEqual(0, arguments.ExcludeRules.Count());
        }

        [TestMethod]
        public void TestExcludeRulsesCommandParam()
        {
            //Init
            CommandLineArgumentsParser parser = new CommandLineArgumentsParser();

            //Act
            CommandArguments arguments = parser.Parse(new[] { "StageJob1.xml", "-exclude", "StableSortRule", "PrefixNamingRule" });

            //Test
            Assert.IsNotNull(arguments);
            Assert.AreEqual("StageJob1.xml", arguments.FileName, true);
            Assert.IsNotNull(arguments.IncludeRules);
            Assert.AreEqual(0, arguments.IncludeRules.Count());
            Assert.IsNotNull(arguments.ExcludeRules);
            Assert.AreEqual(2, arguments.ExcludeRules.Count());
            Assert.AreEqual("StableSortRule", arguments.ExcludeRules[0]);
            Assert.AreEqual("PrefixNamingRule", arguments.ExcludeRules[1]);
        }

        [TestMethod]
        public void TestIncludeAndExcludeRulsesCommandParam()
        {
            //Init
            CommandLineArgumentsParser parser = new CommandLineArgumentsParser();

            //Act
            CommandArguments arguments = parser.Parse(new[] { "StageJob1.xml", "-include", "StableSortRule",
                "-exclude", "PrefixNamingRule" });

            //Test
            Assert.IsNotNull(arguments);
            Assert.AreEqual("StageJob1.xml", arguments.FileName, true);
            Assert.IsNotNull(arguments.IncludeRules);
            Assert.AreEqual(1, arguments.IncludeRules.Count());
            Assert.AreEqual("StableSortRule", arguments.IncludeRules[0]);
            Assert.IsNotNull(arguments.ExcludeRules);
            Assert.AreEqual(1, arguments.ExcludeRules.Count());
            Assert.AreEqual("PrefixNamingRule", arguments.ExcludeRules[0]);
        }
    }
}
